package com.simple.web;

import com.simple.util.JsonConvertUtil;
import com.simple.util.ReportUtil;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Random;

@RestController
public class Controller {


    @RequestMapping("/simple")
    public String simple() throws Exception {
        System.out.println("simple ...........");
        return "SpringBoot";
    }


    @RequestMapping("/simple2")
    public String simple2() throws Exception {
        System.out.println("simple2 ...........");
        Random r = new Random();
        long num = r.nextInt(1000);
        if(num == 745){
            throw new Exception("745");
        }
        return "SpringBoot2";
    }


    @RequestMapping("/deal")
    public String deal(@RequestBody String json){
        return ReportUtil.dealReportData(json,"2019-12-30");
    }

    @RequestMapping("/deal2")
    public String deal2(@RequestBody String json,String jsoncallback){
        return JsonConvertUtil.toJSONString(jsoncallback,ReportUtil.doStatistics(json,"2019-12-28"));
    }

}
